<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/react.development.js" type="text/javascript"></script>
    <script src="../js/react-dom.development.js" type="text/javascript"></script>
    <script src="../js/babel.min.js" type="text/javascript"></script>
</head>

<body>
    <div id="root"></div>
    <script type="text/babel">
        //组件受到react控制 ，使用柯粒化
        class Login extends React.Component {
            state = { username: '', pwd: '' }
            changeData = (name) => {
                return (event)=>{
                    var val = event.target.value;
                    this.setState({
                        [name]: val
                    })
                }
            }
            handleSubmit = (event) => {
                event.preventDefault ? event.preventDefault() : event.returnValue = false;
                const { username, pwd } = this.state;
                console.log(`当前用户名：${username},密码：${pwd}`);
            }
            render() {
                return (
                    <form onSubmit={this.handleSubmit}>
                        <label htmlFor="username">用户名：</label>
                        <input type='text'  name="username" id="username" onChange={this.changeData('username')}/>
                        <label htmlFor="pwd">密码：</label>
                        <input type='password'  name="pwd" id="pwd" onChange={this.changeData('pwd') } />
                        <button>提交</button>
                    </form>
                )
            }
        }
        ReactDOM.render(<Login />, document.getElementById('root'))
    </script>
</body>

</html>